package com.ky.pro.big.data.mr;

import com.ky.pro.big.data.mr.common.EnvConsts;
import com.ky.pro.big.data.mr.mobile.dr.MobileDataRateTool;
import org.apache.commons.cli.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner;

public class MapReduceMain {

    public static void main(String[] args) throws Exception {

        Configuration configuration = new Configuration();

        configuration.set("mapreduce.framework.name", "local");
        configuration.set("yarn.resourcemanager.hostname", "local");

        parseArgs(args);

        int run = ToolRunner.run(configuration, new MobileDataRateTool(), args);
        System.exit(run);

    }

    private static void parseArgs(String[] args) throws ParseException {
        CommandLineParser parser = new BasicParser();
        Options options = new Options();
        options.addOption(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_INPUT_PATH,true, "data input path");
        options.addOption(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_OUTPUT_PATH, true, "result output path");
        CommandLine cmdLine = parser.parse(options, args);
        if(cmdLine.hasOption(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_INPUT_PATH)){
            System.setProperty(EnvConsts.SYS_PROP_MOBILE_DATA_RATE_INPUT_PATH,
                    cmdLine.getOptionValue(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_INPUT_PATH));
        }
        if(cmdLine.hasOption(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_OUTPUT_PATH)){
            System.setProperty(EnvConsts.SYS_PROP_MOBILE_DATA_RATE_OUTPUT_PATH,
                    cmdLine.getOptionValue(EnvConsts.CMD_ARGS_MOBILE_DATA_RATE_OUTPUT_PATH));
        }
    }

}
